home *** CD-ROM | disk | FTP | other *** search
File List | 1991-08-14 | 27.0 KB | 904 lines |
- _SCALIN╟ AN─ PRINTIN╟ FA╪E╪ FASTER_
- b∙ Greτ Pickles
-
- [COMPLET┼ SOURCE]
-
-
- [LISTING ONE]
-
- ;--------------------------------------------------------------------
- ; Scale2To3 (c) Copyright 1991, Greg Pickles, All Rights Reserved
- ;
- ; C callable assembly language routine to expand 2 lines of 200 DPI
- ; bitmap to 3 lines of 300 DPI bitmap. Assumes that all memory for
- ; storing the lines is allocated outside this routine.
- ;--------------------------------------------------------------------
- .model large,c
- .286
- .data
- ;-----------------------------------------------------------
- ; The following table defines the output bit map to use for
- ; each incoming 2x2 bit section. The table is organized
- ; as groups of 4 bytes even though only the first 3 in
- ; each group is used.
- ;-----------------------------------------------------------
- MapTbl dw 0000000000000000b ;0
- dw 0000000000000000b
- dw 0000000000000000b
- dw 0
-
- dw 0000001100000000b ;1
- dw 0000001100000000b
- dw 0000000000000000b
- dw 0
-
- dw 0000011000000000b ;2
- dw 0000011000000000b
- dw 0000000000000000b
- dw 0
-
- dw 0000011100000000b ;3
- dw 0000011100000000b
- dw 0000000000000000b
- dw 0
-
- dw 0000000000000000b ;4
- dw 0000001100000000b
- dw 0000001100000000b
- dw 0
-
- dw 0000001100000000b ;5
- dw 0000001100000000b
- dw 0000001100000000b
- dw 0
-
- dw 0000011000000000b ;6
- dw 0000011100000000b
- dw 0000001100000000b
- dw 0
-
- dw 0000011100000000b ;7
- dw 0000011100000000b
- dw 0000001100000000b
- dw 0
-
- dw 0000000000000000b ;8
- dw 0000011000000000b
- dw 0000011000000000b
- dw 0
-
- dw 0000001100000000b ;9
- dw 0000011100000000b
- dw 0000011000000000b
- dw 0
-
- dw 0000011000000000b ;a
- dw 0000011000000000b
- dw 0000011000000000b
- dw 0
-
- dw 0000011100000000b ;b
- dw 0000011100000000b
- dw 0000011000000000b
- dw 0
-
- dw 0000000000000000b ;c
- dw 0000011100000000b
- dw 0000011100000000b
- dw 0
-
- dw 0000001100000000b ;d
- dw 0000011100000000b
- dw 0000011100000000b
- dw 0
-
- dw 0000011000000000b ;e
- dw 0000011100000000b
- dw 0000011100000000b
- dw 0
-
- dw 0000011100000000b ;f
- dw 0000011100000000b
- dw 0000011100000000b
- dw 0
-
- .code
- ;--------------------------------------------------------------------
- ; Scale2to3
- ; Takes an array of bytes containing two lines of image
- ; bit data and generates 3 lines of image bit data by
- ; scaling the data in a 2:3 ratio in both directions.
- ;
- ; parameters
- ; pointer to input array
- ; pointer to output array (assumed to be already allocated)
- ; >>>> This pointer must be word aligned!! <<<<
- ; number of bytes per line of input data
- ; invert flag - if non-zero (TRUE) incoming data will be inverted
- ;
- ; C prototype
- ; void Scale2to3(char far*,char far*,short,short);
- ;
- ; returns
- ; nothing
- ;--------------------------------------------------------------------
- public Scale2to3
- Scale2to3 proc uses si di ds,pIn:PTR,pOut:PTR,nBytes:WORD,InvFlg:Word
-
- LOCAL OuterCnt:WORD
-
- S23_0:
- mov ax,nBytes ;get number of bytes in input line
- mov OuterCnt,ax ;set outer loop count
-
- mov dx,ax ;mult AX by 3/2 and put result in DX
- shr ax,1 ;div AX by 2
- jnc S23_10 ;if carry, then there is a fractional
- inc ax ; bytein the result, so inc for it
- S23_10: add dx,ax ;save # of bytes in output line in dx
-
- ;fill the output buffer with 0
- mov cx,dx ;multiply output line size by 3
- shl cx,1
- add cx,dx
- mov bx,cx ;save CX to test for odd value later
- shr cx,1 ;divide CX by 2 to get word count
- les di,pOut ;get pointer to output buffer
- sub ax,ax ;get fill value
- rep stosw
- test bl,1 ;see if extra byte to fill
- jz S23_15
- stosb
-
- S23_15: mov ax,@data
- mov ds,ax
- mov si,offset MapTbl
- mov cl,13 ;amount to shift initial output value
-
- ;top of loop that processes a byte of input
- ; register usage:
- ; AX = input data and output data
- ; BX = ofset into map table
- ; CH = inner loop counter
- ; CL = shift count for this output group
- ; DX = size of output line
- ; DS:SI pointer to map table
- ; ES:DI pointer to output word
- S23_30: les di,pIn ;get pointer to 1st input line
- mov ah,byte ptr es:[di] ;get data from line 1
- add di,nBytes
- mov al,byte ptr es:[di] ;get data from line 2
-
- test InvFlg,0ffffh ;see if we need to invert
- jz S23_35
- not ax
-
- S23_35: mov ch,4 ;do 4 2-bit segments in next loop
- mov es,word ptr pOut+2 ;get segment address of output
-
- S23_40: rol ax,2 ;bits we want are in 0,1,8,9
- push ax
- and ax,303h ;mask out other bits
- shl ah,2 ;move bits from 8,9 to 10,11
- or al,ah ;or them into al
- sub ah,ah ;clear ah
- shl ax,3 ;ax now has offset into enlarge table
- mov bx,ax
-
- mov ax,[si+bx] ;get output value
- rol ax,cl ;shift it
- mov di,word ptr pOut
- or es:[di],ax ;or into output
-
- add di,dx ;get pointer to line 2 of output
- mov ax,[si+bx+2] ;get output value
- rol ax,cl ;shift it
- or es:[di],ax ;or into output
-
- add di,dx ;get pointer to line 3 of output
- mov ax,[si+bx+4] ;get output value
- rol ax,cl ;shift it
- or es:[di],ax ;or into output
-
- pop ax
- ;adjust the shift count for the output data
- ;and the output pointer, if necessary
- cmp cl,1 ;see if we need to bump output pointer
- ja S23_60 ;jump if just need to adjust count
- ;CL is either 0 or 1 so it must become
- ; either 13 or 6, respectively
- ; NOTE: we are later going to sub 3
- ; so set CL what we want + 3
- mov cl,9 ;assume CL was 1
- je S23_50 ;jump if CL=1
- mov cl,16 ;opps! guessed wrong so make it 13
- inc word ptr pOut ;when CL goes from 0 to 13, need to
- ; bump the output pointer by 2
- S23_50: inc word ptr pOut ;increment output pointer
- S23_60: sub cl,3
-
- dec ch ;decrement inner loop counter
- jnz S23_40 ;jump to inner loop if not 0
-
- inc word ptr pIn ;increment input pointer
- dec OuterCnt ;decrement outer loop counter
- jnz S23_30
-
- ret
-
- Scale2to3 endp
- end
-
-
- [LISTING TWO]
-
-
- /*******************************************************************
- * BUFIO.H (c) Copyright 1991, Greg Pickles, All Rights Reserved
- *
- * Header file buffered file I/O.
- *******************************************************************/
-
- /*---------------------------------------------------------------
- * "standard" data types
- *--------------------------------------------------------------*/
- typedef unsigned char UCHAR;
- typedef unsigned short USHORT;
- typedef short SHORT;
- #define TRUE 1
- #define FALSE 0
-
-
- #define FILEBUFSIZE 8192
-
- /*---------------------------------------------------------------
- * structure for buffered file I/O
- *--------------------------------------------------------------*/
- typedef struct {
- int hFile; // DOS file handle
- SHORT sMode; // how file is opened
- SHORT sBufCnt; // count of "active" bytes in buf
- UCHAR *pucBuf; // pointer to next byte
- UCHAR aucBuf[FILEBUFSIZE]; // buffer
- }FILEBUFFER;
-
- /*---------------------------------------------------------------
- * prototypes
- *--------------------------------------------------------------*/
- int GetBufCh( FILEBUFFER* );
- int BufWrite( FILEBUFFER*, UCHAR*, SHORT );
- int BufFlush( FILEBUFFER* );
- FILEBUFFER *FileOpen( char*, SHORT );
- int FileClose( FILEBUFFER* );
-
-
- [LISTING THREE]
-
-
- /*******************************************************************
- * BUFIO.C (c) Copyright 1991, Greg Pickles, All Rights Reserved
- *
- * Simple buffered file I/O.
- *******************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <memory.h>
- #include <malloc.h>
- #include <fcntl.h>
- #include <io.h>
- #include <sys\types.h>
- #include <sys\stat.h>
-
- #include "bufio.h"
-
- /*******************************************************************
- * GetBufCh
- * Read the next char from a file using a buffer. Reads the file as
- * necessary. Assumes that the file is already open.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pstrcF pointer to the FILEBUFFER structure for the file
- *
- * Return Value
- * ------------
- * The next character from the file, if available
- * EOF if no characters are available or error
- *******************************************************************/
- int GetBufCh( FILEBUFFER *pstrcF )
- {
- if (pstrcF->sBufCnt == 0)
- {
- if ( (pstrcF->sBufCnt =
- read(pstrcF->hFile,pstrcF->aucBuf,FILEBUFSIZE)) == 0 )
- return EOF;
- pstrcF->pucBuf=pstrcF->aucBuf;
- }
- pstrcF->sBufCnt--;
- return (int)*(pstrcF->pucBuf++);
- }
-
- /*******************************************************************
- * BufWrite
- * Write a buffer of characters to an output file via a file buffer
- * structure.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pstrcF pointer to the FILEBUFFER structure for the file
- * pbBuf pointer to the array of bytes to write
- * sCnt number of bytes to write
- *
- * Return Value
- * ------------
- * 0 if success, non-0 if an error occurs
- *******************************************************************/
- int BufWrite( FILEBUFFER *pstrcF, UCHAR *pbBuf, SHORT sCnt )
- {
- int iRslt;
-
- while (sCnt > pstrcF->sBufCnt)
- {
- memcpy( pstrcF->pucBuf, pbBuf, pstrcF->sBufCnt );
- sCnt -= pstrcF->sBufCnt;
- pbBuf += pstrcF->sBufCnt;
- pstrcF->sBufCnt = 0;
- if (iRslt = BufFlush(pstrcF))
- return (iRslt);
- }
- if (sCnt > 0)
- {
- memcpy( pstrcF->pucBuf, pbBuf, sCnt );
- pstrcF->pucBuf += sCnt;
- pstrcF->sBufCnt -= sCnt;
- }
- return 0;
- }
-
- /*******************************************************************
- * BufFlush
- * Flush an output buffer to disk.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pstrcF pointer to the FILEBUFFER structure for the file
- *
- * Return Value
- * ------------
- * 0 if success, non-0 if an error occurs
- *******************************************************************/
- int BufFlush( FILEBUFFER *pstrcF )
- {
- int iRslt;
- if (pstrcF->sBufCnt != FILEBUFSIZE)
- {
- iRslt = write(pstrcF->hFile, pstrcF->aucBuf,
- FILEBUFSIZE-pstrcF->sBufCnt);
- if (iRslt != FILEBUFSIZE-pstrcF->sBufCnt)
- return errno;
- pstrcF->pucBuf = pstrcF->aucBuf;
- pstrcF->sBufCnt = FILEBUFSIZE;
- }
- return 0;
- }
-
- /*******************************************************************
- * FileOpen
- * Open a file for input or output using a file buffer structure.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pszFileName pointer to file name
- * sMode 0 for read, 1 for write
- *
- * Return Value
- * ------------
- * pointer to allocated file buffer structure if success
- * NULL if error
- *******************************************************************/
- FILEBUFFER *FileOpen( char *pszFileName, SHORT sMode )
- {
- FILEBUFFER *pstrcFile;
-
- // allocate file buffer STRCUTURE
- if ( (pstrcFile=malloc(sizeof(FILEBUFFER))) == NULL )
- {
- printf("Error allocating file buffer FOR %s\n",pszFileName);
- return NULL;
- }
- pstrcFile->pucBuf=pstrcFile->aucBuf;
- if (sMode)
- {
- pstrcFile->sBufCnt=FILEBUFSIZE;
- pstrcFile->hFile = open(pszFileName,
- O_BINARY|O_CREAT|O_TRUNC|O_WRONLY,S_IWRITE);
- }
- else
- {
- pstrcFile->sBufCnt=0;
- pstrcFile->hFile = open(pszFileName,O_BINARY|O_RDONLY);
- }
- if (pstrcFile->hFile == -1)
- {
- printf("Error opening '%s'\n",pszFileName);
- free(pstrcFile);
- return NULL;
- }
- pstrcFile->sMode = sMode;
- return pstrcFile;
- }
-
- /*******************************************************************
- * FileClose
- * Close a file.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pstrcFile pointer to FILEBUFFER for the file
- *
- * Return Value
- * ------------
- * 0 if success, non-0 if an error occurs
- *******************************************************************/
- int FileClose( FILEBUFFER *pstrcFile )
- {
- int iRslt = 0;
-
- if (pstrcFile->sMode == 1)
- BufFlush(pstrcFile);
- iRslt = close(pstrcFile->hFile);
- free(pstrcFile);
- return iRslt;
- }
-
-
- [LISTING FOUR]
-
- /*******************************************************************
- * PCXHP.H (c) Copyright 1991, Greg Pickles, All Rights Reserved
- *
- * Header file for FAX image print program.
- *******************************************************************/
- /*-------------------------------------------------------------
- * structure to pass control information
- *------------------------------------------------------------*/
- typedef struct {
- SHORT sXpos; // x pos for image on page in pixels
- SHORT sYpos; // y pos for image on page in pixels
- SHORT sInv; // TRUE to invert image
- SHORT sEndAdjust; // number of bytes at the end of a raster line
- // to adjust because they are beyond the end
- // of the actual image
- SHORT sAdjOffset; // offset in line of first byte to adjust
- UCHAR ucMask; // mask to OR in to the first byte that is
- // adjusted (image may end in middle of byte)
- }OPTIONS;
-
- /*-------------------------------------------------------------
- * PCX file header
- *------------------------------------------------------------*/
- typedef struct {
- UCHAR ucPcxId; // PCX ID, always 0x0a
- UCHAR ucVer; // PCX version
- UCHAR ucEncMeth; // 1 = run length
- UCHAR ucBPP; // bits per pixel
- USHORT usUpLeftX, usUpLeftY; // position of upper left corner
- USHORT usLoRightX, usLoRightY; // position of lower right corner
- USHORT usDispXRes, usDispYRes; // resolution of display
- UCHAR aucPalette[48]; // palette data
- UCHAR ucRes;
- UCHAR ucNumPlanes; // number of bit planes of data
- USHORT usBytePerLine; // # bytes in an raster line
- UCHAR ucRes2[60];
- }PCX_HDR;
-
- /*-------------------------------------------------------------
- * Prototypes
- *------------------------------------------------------------*/
- int PCXToHP(char*, FILEBUFFER*, OPTIONS*);
- void usage(void);
- PCX_HDR *PcxReadHeader(PCX_HDR*, FILEBUFFER*);
- void pcx_print_header(PCX_HDR*);
- UCHAR *pcx_alloc_line(PCX_HDR*, SHORT);
- int PcxReadLines(PCX_HDR*, UCHAR*, FILEBUFFER*, SHORT, OPTIONS*);
- UCHAR *pcx_test_line(PCX_HDR*, UCHAR*, SHORT, SHORT);
- UCHAR *ScanNE(UCHAR*, UCHAR, int);
- int IndexNE(UCHAR*, UCHAR, int);
- int CntREQ(UCHAR*, UCHAR, int);
- int main(int, char**);
-
- void Scale2to3(char far*,char far*,short,short);
-
-
- [LISTING FIVE]
-
-
- /*******************************************************************
- * PCXHP.C (c) Copyright 1991, Greg Pickles, All Rights Reserved
- *
- * FAX to LaserJet II image print program.
- *******************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <memory.h>
- #include <malloc.h>
- #include <fcntl.h>
- #include <io.h>
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <conio.h>
-
- #include "bufio.h"
- #include "pcxhp.h"
-
- /*******************************************************************
- * PCXToHP
- * Process a PCX file
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pszFileName pointer to the input file name
- * pstrcOutFile pointer to output file buffer structure
- * pstrcOpt pointer to OPTIONS struc for processing this file
- *
- * Return Value
- * ------------
- * 0 if successful, non-0 if error
- *******************************************************************/
- int PCXToHP(char *pszFileName, FILEBUFFER *pstrcOutFile,
- OPTIONS *pstrcOpt)
- {
- FILEBUFFER *pstrcInFile;
- PCX_HDR strcHdr;
- SHORT i, k, sXsize, sYsize, sLineBytes, sExpLineSize;
- UCHAR *pucLine, *pucExpBuf;
- int iCurX = -1, iCurY = -1;
- int iNewX, iNewY, iFront, iBack;
- char szFileName[80];
- char szHpLineLead[20];
- char szHpPos[50];
-
- static char szPosFmtFXYO[] = "\x01b*p%dx%dY\x01b*r1A";
- static char szPosFmtY[] = "\x01b*p%dY";
- static char szGrDataFmt[]= "\x01b*b%dW";
- static char szEndGr[] = "\x01b*rB";
- static char szRes300[] = "\x01b*t300R";
-
-
- strcpy(szFileName, pszFileName); // make local copy of name
- if (strchr(szFileName,'.') == NULL) // add .PCX if needed
- strcat(szFileName,".pcx");
-
- // allocate input file buffer and open file
- if ( (pstrcInFile=FileOpen(szFileName,0)) == NULL )
- return 1;
-
- if (PcxReadHeader(&strcHdr,pstrcInFile) == NULL)
- {
- fprintf(stderr,"Error reading PCX header in file '%s'\n",
- szFileName);
- close(pstrcInFile->hFile);
- return 3;
- }
-
- if (strcHdr.ucNumPlanes != 1)
- {
- fprintf(stderr,"Error: Not a monochrome PCX file.\n");
- close(pstrcInFile->hFile);
- return 5;
- }
- // extract size of line, compute number of rows
- // allocate buffer for 2 input lines
- sLineBytes = strcHdr.usBytePerLine;
- sYsize = strcHdr.usLoRightY - strcHdr.usUpLeftY + 1;
- pucLine = malloc(2*sLineBytes);
-
- // determine whether any bits/bytes need to be masked
- // at the end of a decompressed line
- sXsize = (strcHdr.usLoRightX - strcHdr.usUpLeftX + 1);
- if ( sXsize/8 < sLineBytes )
- {
- pstrcOpt->sEndAdjust = sLineBytes - sXsize/8;
- pstrcOpt->sAdjOffset = sXsize/8;
- pstrcOpt->ucMask = (UCHAR) (0xff >> sXsize%8);
- }
- // compute length of scaled line and allocate buffer
- sExpLineSize = strcHdr.usBytePerLine + (strcHdr.usBytePerLine/2) +
- ((strcHdr.usBytePerLine & 1) ? 1 : 0);
- pucExpBuf = malloc(sExpLineSize*3);
-
- // set HP graphics resolution to 300 DPI
- BufWrite(pstrcOutFile,szRes300, strlen(szRes300));
-
- // init position on page
- iNewX = pstrcOpt->sXpos;
- iNewY = pstrcOpt->sYpos;
-
- for (i=0; i<sYsize; i+=2)
- {
- if ( !PcxReadLines(&strcHdr, pucLine, pstrcInFile, 2, pstrcOpt) )
- break;
- Scale2to3(pucLine,pucExpBuf,sLineBytes,pstrcOpt->sInv);
-
- for (k=0; k<3; k++)
- {
- if ((iFront=IndexNE(pucExpBuf+k*sExpLineSize,0,sExpLineSize)) >= 0)
- {
- iNewX = pstrcOpt->sXpos + iFront*8;
- iBack=CntREQ(pucExpBuf+(k+1)*sExpLineSize-1,0,sExpLineSize);
- if (iNewX != iCurX)
- {
- sprintf(szHpPos,szPosFmtFXYO,iNewX,iNewY);
- BufWrite(pstrcOutFile,szHpPos,strlen(szHpPos));
- iCurX = iNewX;
- iCurY = iNewY;
- }
- else if (iNewY != iCurY)
- {
- sprintf(szHpPos,szPosFmtY,iNewY);
- BufWrite(pstrcOutFile,szHpPos,strlen(szHpPos));
- iCurY = iNewY;
- }
- // note: a possible optimization is to remember the
- // previous leadin string, value of iFront,
- // and leadin string length and only create
- // them when they change
- sprintf(szHpLineLead,szGrDataFmt, sExpLineSize-iFront-iBack);
-
- BufWrite(pstrcOutFile,szHpLineLead,strlen(szHpLineLead));
- BufWrite(pstrcOutFile,pucExpBuf+k*sExpLineSize+iFront,
- sExpLineSize-iFront-iBack);
- iCurY++;
- }
- iNewY++;
- }
-
- }
-
- BufWrite(pstrcOutFile,szEndGr,strlen(szEndGr));
- BufWrite(pstrcOutFile,"\f",1);
-
- free(pucLine);
- free(pucExpBuf);
- FileClose(pstrcInFile);
- return 0;
- }
-
- /*******************************************************************
- * usage
- * Displays usage help and returns to system.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * none
- *
- * Return Value
- * ------------
- * none
- *******************************************************************/
- void usage(void)
- {
- printf("PCXHP\n");
- printf(" Given a .PCX file, this program creates a file which can be\n");
- printf(" sent to an HP LaserJet printer to print the image.\n");
- printf(" PCXHP [-xX] [-yY][-d] [-i] [-ofilename] filename\n");
- printf(" Options include: (units) [default]\n");
- printf(" -xPOS set horizontal position (pixels from left) [0]\n");
- printf(" -yPOS set vertical position (pixels from bottom) [0]\n");
- printf(" -d dump PCX file info to stdout [off]\n");
- printf(" -i sInv image [off]\n");
- printf(" -oFIL set output filename, or use SET PCXHP=filename\n");
- exit(1);
- }
-
- /*******************************************************************
- * PcxReadHeader
- * Reads the header of a PCX file. Assumes the file is already open
- * and its handle is in the file buffer structure.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pstrcHdr pointer to struct in which to store the header
- * pstrcF pointer to file buffer struct for the file
- *
- * Return Value
- * ------------
- * pointer to the header structure, if successful
- * NULL if error
- *******************************************************************/
- PCX_HDR *PcxReadHeader(PCX_HDR *pstrcHdr, FILEBUFFER *pstrcF)
- {
- lseek(pstrcF->hFile,0L,SEEK_SET);
- if (read(pstrcF->hFile,(char*)pstrcHdr,sizeof(PCX_HDR))
- != sizeof(*pstrcHdr))
- return NULL;
- else
- return pstrcHdr;
- }
-
- /*******************************************************************
- * PcxReadLines
- * Reads and expands the next N line from the PCX file. Assumes
- * that the file pointer is positioned at the point in the file at
- * which to begin reading. Performs data expansion as necessary.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pstrcHdr pointer to PCX header struct for the file
- * pbLine pointer to the buffer in which to put lines
- * pstrcF pointer to the opened FILEBUFFER for the file
- * sLines number of lines to read and expand
- *
- * Return Value
- * ------------
- * TRUE if success, FALSE if our of data
- *******************************************************************/
- int PcxReadLines(PCX_HDR *pstrcHdr, UCHAR *pucLine, FILEBUFFER *pstrcF,
- SHORT sLines, OPTIONS *pstrcOpt)
- {
- int iData, iData2;
- UCHAR *pucDst, *pucLineStart;
- USHORT usLSize = pstrcHdr->usBytePerLine;
- int i, j;
-
- for (j=0, pucDst=pucLine; j<sLines; j++)
- {
- for (i=0, pucLineStart=pucDst; i<usLSize; )
- {
- // if we get EOF on the first line, return FALSE
- // to indicate we're done, otherwise fill the
- // rest of the lines with 0xff (i.e. blank)
- if ((iData=GetBufCh(pstrcF)) == EOF)
- {
- if ( (j > 0) || (i > 0) )
- {
- memset(pucDst,0xff,usLSize-i);
- i = usLSize;
- pucDst += (usLSize-i);
- }
- else
- return FALSE;
- }
- else
- {
- if ((iData & 0xc0) == 0xc0) // check for run length
- {
- // read data to be repeated; if EOF, return FALSE
- if ((iData2=GetBufCh(pstrcF)) == EOF)
- return FALSE;
- memset(pucDst, (UCHAR)iData2, iData & 0x3f);
- pucDst += iData & 0x3f;
- i += iData & 0x3f;
- }
- else
- {
- *pucDst++ = (UCHAR)iData;
- i++;
- }
- }
- }
- if (i=pstrcOpt->sEndAdjust)
- {
- pucLineStart += pstrcOpt->sAdjOffset;
- *pucLineStart |= pstrcOpt->ucMask;
- while (--i)
- *(++pucLineStart) = 0xff;
- }
- }
- return TRUE;
- }
-
- /*******************************************************************
- * IndexNE
- * Scans a buffer for the first byte not equal to a specified byte.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pbBuf pointer to the buffer to test
- * bVal value to test for
- * iCount number of bytes to test
- *
- *
- * Return Value
- * ------------
- * -1 if the buffer contains only the specified byte
- * otherwise offset of the first byte that is not the specified byte
- *******************************************************************/
- int IndexNE(UCHAR *bBuf, UCHAR bVal, int iCount)
- {
- int iOrig = iCount;
-
- while (iCount && (*bBuf == bVal))
- {
- iCount--;
- bBuf++;
- }
- if (iCount)
- return iOrig-iCount;
- return -1;
- }
-
- /*******************************************************************
- * CntREQ
- * Counts the number of bytes equal to a specified byte from a
- * starting point in memory backwards.
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * pbBuf pointer to the (end of the) buffer to test
- * bVal value to test for
- * iCount number of bytes to test
- *
- * Return Value
- * ------------
- * number of bytes found that are equal to the specified byte
- *******************************************************************/
- int CntREQ(UCHAR *bBuf, UCHAR bVal, int iCount)
- {
- int iOrig = iCount;
-
- while (iCount && (*bBuf == bVal))
- {
- iCount--;
- bBuf--;
- }
- return iOrig-iCount;
- }
-
- /*******************************************************************
- * main
- *
- * Parameters Description
- * ----------------------------------------------------------------
- * argc argument character count
- * argp pointer to array of pointers to args
- *
- *
- * Return Value
- * ------------
- * 1 if error in args or opening output file
- * otherwise result of PCXToHP
- *******************************************************************/
- int main(int argc, char *argv[])
- {
- int i;
- FILEBUFFER *OutFile;
- char *outfname = NULL;
- char *filename = NULL;
-
- static OPTIONS Opt = {0,0,TRUE,0,0,0};
-
- if (argc < 2)
- usage();
-
- for (i=1; i<argc; i++)
- {
- if (argv[i][0] == '-' || argv[i][0] == '/')
- switch (toupper(argv[i][1]))
- {
- case 'X': Opt.sXpos = atoi(argv[i]+2); break;
- case 'Y': Opt.sYpos = atoi(argv[i]+2); break;
- case 'I': Opt.sInv = !Opt.sInv; break;
- case 'O': outfname=argv[i]+2; break;
- case '?': usage(); break;
- default: fprintf(stderr, "Unknown option %s\n",argv[i]);
- usage();
- break;
- }
- else
- filename = argv[i];
- }
-
- if ( (outfname == NULL) && ((outfname = getenv("PCXHP")) == NULL) )
- outfname = "prn";
- if ( (OutFile=FileOpen(outfname,1)) == NULL )
- exit(1);
-
- i = PCXToHP(filename, OutFile, &Opt);
-
- FileClose(OutFile);
- return i;
- }
-